//
//  NKRootViewController.m
//  NewKY
//
//  Created by Dee on 2016/11/12.
//  Copyright © 2016年 Dee. All rights reserved.
//

#import "NKRootViewController.h"
#import "NKNewFeatureView.h"
#import "NKLeftViewController.h"
#import "NKMainNavigation.h"
@interface NKRootViewController ()

@end

@implementation NKRootViewController


-(void)awakeFromNib{
    
    [super awakeFromNib];
    
        //初始化框架
    LMSideBarDepthStyle *sideBarDepthStyle = [LMSideBarDepthStyle new];
    sideBarDepthStyle.menuWidth = 250;
    sideBarDepthStyle.closedScale = 0.95;
        //创建侧滑控制器
    NKLeftViewController *leftMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"NKLeftViewController"];
        //创建导航控制器
    NKMainNavigation *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:@"NKMainNavigation"];
        //设置属性
    [self setPanGestureEnabled:YES];
    [self setDelegate:self];
        //添加到侧滑
    [self setMenuViewController:leftMenuViewController forDirection:LMSideBarControllerDirectionLeft];
        //添加到导航
    [self setSideBarStyle:sideBarDepthStyle forDirection:LMSideBarControllerDirectionLeft];
    
        //设置内容控制器
    [self setContentViewController:navigationController];
        //内容控制器调用主页控制器
    [navigationController showHomeViewController];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
    NSInteger status = [[userDefaults objectForKey:@"USER_STATUS"]intValue];
    
        //游客登录每次显示新特性
        //登录后不显示
    if (!status) {

        [userDefaults setObject:@"1" forKey:@"FIRST_START"];

        if([[userDefaults objectForKey:@"FIRST_START"]isEqualToString:@"1"]){
            
            NSLog(@"%@",[userDefaults objectForKey:@"FIRST_START"]);
            [userDefaults setObject:@"0" forKey:@"FIRST_START"];
                //显示出新特性界面
            [self showNewFeatureView];
        }
        
    }
    
}

#pragma mark - 显示新特性界面
-(void)showNewFeatureView{
    
    //创建新特性界面
    NKNewFeatureView *vNew = [[NKNewFeatureView alloc] initWithFrame:self.view.bounds];
    
    //    vNew.backgroundColor = [UIColor orangeColor];
    
    //把视频地址数组传递给新特性界面
    vNew.playerUrls = [self getNewFeaturePlayerUrls];
    
    //把新特性界面添加到根视图
    [self.view addSubview:vNew];
}


#pragma mark - 提供视频地址数组的方法
-(NSArray *)getNewFeaturePlayerUrls{
    
    int count = 4;
    
    //根据视频的数量来循环创建视频地址对象
    //并且添加到数组中
    NSMutableArray *UrlsM = [NSMutableArray array];
    for (int i = 0; i < count; i++) {
        
        //1> 拼接视频的名字
        NSString *playerName = [@"x" stringByAppendingFormat:@"%d.mp4",i+1];
        
        //2>获取视频本地路径
        NSURL *url = [[NSBundle mainBundle] URLForResource:playerName withExtension:nil];
        
        //3> 添加到数组
        [UrlsM addObject:url];
    }
    
    return UrlsM;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
